mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		down: {
			callback: pulldownRefresh
		},
		up: {
			contentrefresh: '正在加载...',
			callback: pullupRefresh
		}
	}
});
var kaiguan = false
var news = new Vue({
	el: '#pullrefresh',
	data: {
		list: [],
	},
	mounted: function() {
		$(".guanli").on("tap", function() {
			qiehuan($(this))
		})
	},
	beforeUpdate: function() {
		updata()
	},
	updated: function() {
		updata()
	}
})

function updata() {
	$(".remove").on("tap", function() {
		var data = ""
		for(var i = 0; i < $(".check").length; i++) {
			data += $(".check").eq(i).attr("newsid") + ","
		}
		common.ajax("student/delete", {
			token: common.token,
			uid: common.uid,
			messageIds: data.slice(0, data.length - 1)
		}, function(data) {
			if(data.code == 200) {
				$(".check").parents(".news").remove();
				
				$(".removenum").text($(".check").length)
				if($(".news").length == 0) {
					qiehuan($(this))
				}
			} else {
				mui.toast(data.message)
			}
		})
	})
	$(".news").on("tap", function() {
		$(this).find(".checkeds").toggleClass("check")
		$(".removenum").text($(".check").length)
	})

}


function qiehuan(index) {
	$(".checkeds").removeClass("check")
	$(".removenum").text($(".check").length)
	if(index.text() == "管理") {
		index.text('完成')
		kaiguan = true
	} else {
		kaiguan = false
		index.text('管理')
	}
	$(".checkeds").toggle()
	$(".remove").toggle()
}

/**
 * 下拉刷新具体业务实现
 */
var temp = 1

function pulldownRefresh() {
	if(kaiguan) {
		mui('#pullrefresh').pullRefresh().endPulldownToRefresh()
		return
	}
	setTimeout(function() {
		mui('#pullrefresh').pullRefresh().refresh(true)
		mui('#pullrefresh').pullRefresh().endPulldownToRefresh()
	}, 800)
}
/**
 * 上拉加载具体业务实现
 */
function pullupRefresh() {
	if(kaiguan) {
		mui('#pullrefresh').pullRefresh().endPullupToRefresh()
		return
	}
	common.ajax("student/querySystemMsg", {
		uid: common.uid,
		token: common.token,
		page: ++temp,
		pageSize: 4
	}, function(data) {
		if(data.code == 200) {
			if(!data.data.hasNextPage) {
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true)
			} else {
				mui('#pullrefresh').pullRefresh().endPullupToRefresh()
			}
			for(var i = 0; i < data.data.list.length; i++) {
				news.list.push(data.data.list[i])
			}
		} else {
			mui.toast(data.message)
		}
	}, "get")
}

if(mui.os.plus) {
	mui.plusReady(function() {
		setTimeout(function() {
			mui('#pullrefresh').pullRefresh().pullupLoading();
		}, 10);

	});
} else {
	mui.ready(function() {
		mui('#pullrefresh').pullRefresh().pullupLoading();
	});
}